package org.payeco.risk.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PayecoRiskValidateAspect {
	private final static Logger log = LoggerFactory
			.getLogger(PayecoRiskValidateAspect.class);

	@Pointcut("execution(public * org.payeco.risk..*forwardValidate())")
	public void excudeService() {

	}

	@Before("excudeService()")
	public void deBefore() {
		System.out.println("调用方法开始。。。 " );
	}

	@AfterReturning(returning = "ret", pointcut = "excudeService()")
	public void doAfterReturning(Object ret) throws Throwable {
		// 处理完请求，返回内容
		System.out.println("方法的返回值 : " + ret);
	}

	// 后置异常通知
	@AfterThrowing("excudeService()")
	public void throwss(JoinPoint jp) {
		System.out.println("方法异常时执行.....");
	}

	// 后置最终通知,final增强，不管是抛出异常或者正常退出都会执行
	@After("excudeService()")
	public void after(JoinPoint jp) {
		System.out.println("方法最后执行.....");
	}

	// 环绕通知,环绕增强，相当于MethodInterceptor
	@Around("excudeService()")
	public Object arround(ProceedingJoinPoint pjp) {
		System.out.println("方法环绕start.....");
		try {
			Object o = pjp.proceed();
			System.out.println("方法环绕proceed，结果是 :" + o);
			return o;
		} catch (Throwable e) {
			e.printStackTrace();
			return null;
		}
	}
}
